package it.francescogabbrielli.android.solidalapp.actions;

import android.util.Log;
import it.francescogabbrielli.android.solidalapp.Action;
import it.francescogabbrielli.android.solidalapp.EndpointsUtils;
import it.francescogabbrielli.android.solidalapp.R;
import it.francescogabbrielli.android.solidalapp.SolidalApp.DataKey;
import it.francescogabbrielli.android.solidalapp.home.HomeActivity;
import it.francescogabbrielli.android.solidalapp.requestendpoint.Requestendpoint;
import it.francescogabbrielli.android.solidalapp.requestendpoint.model.Request;

public class EndpointsRemoveRequest extends Action {

	@Override
	public void execute() throws Exception {
		Request req = getModel(Request.class);
		req.setCanceled(true);
		Requestendpoint endpoint = EndpointsUtils.buildEndpoint(Requestendpoint.class);
		Request ret = endpoint.updateRequest(req).execute();
		setModel(ret);
		Log.d(getClass().getSimpleName(), "Request canceled: "+req.getMessage());
	}

	@Override
	public void onPostExecute() throws Exception {
		app.alert(R.string.request_canceled_message);
		app.setData(DataKey.REQUEST, null);
		refireActivity(HomeActivity.class);
	}

}
